package com.cea.papyrustest.uml.createcommand;

import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Operation;

import com.cea.papyrus.core.commands.UMLElementCreateCommand;

/**
 * Test class for {@link Operation} creation command
 * @author Remi Schnekenburger
 */
public class OperationCreateCommandTest extends PapyrusCommandTest {

	private org.eclipse.uml2.uml.Class class_;

	/**
	 * Default constructor
	 * @param name the name of the test case
	 */
	public OperationCreateCommandTest(String name) {
		super(name);	
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		// creates a class
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Class.class,model);
		stack.execute(papyrusCommand);
		this.class_ = (org.eclipse.uml2.uml.Class)((UMLElementCreateCommand)papyrusCommand).getElement();

		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Operation.class, class_);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		// execute command
		stack.execute(papyrusCommand);
		Element clazz=class_.getOwnedOperation("Operation_0", null, null);
		assertNotNull("the operation is created",clazz);
		assertTrue("this is not a operation",((clazz)instanceof Operation));

		// undo command
		stack.undo();
		assertNull("the operation exist!", class_.getOwnedOperation("Operation_0", null, null));

		// redo command
		stack.redo();
		clazz=class_.getOwnedOperation("Operation_0", null, null);
		assertNotNull("the operation is re-added to class",clazz);
		assertTrue("this is not a operation",((clazz)instanceof Operation));

	}

}
